<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<%@include file="/WEB-INF/taglibs/common/taglibs.jsp" %>

<head>
    <title>New Transactions</title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
    <link rel="stylesheet" href="<c:url value="/css/styles.css"/>"/>
    <script src="<c:url value="/javascripts/common.js"/>" type="text/javascript"></script>

    <link rel="stylesheet"
          href="<c:url value="/javascripts/jscalendar/theme/calendar-system.css"/>"/>
    <script src="<c:url value="/javascripts/jscalendar/calendar-cfg.js"/>" type="text/javascript"></script>
    <script src="<c:url value="/javascripts/calendar.js"/>" type="text/javascript"></script>
    <script
            src="<c:url value="/javascripts/jscalendar/lang/calendar-en.js"/>" type="text/javascript"></script>
    <script src="<c:url value="/javascripts/jscalendar/calendar-setup.js"/>" type="text/javascript"></script>
    <script src="<c:url value="/javascripts/jquery-1.4.4.js"/>" type="text/javascript"></script>
	<script type="text/javascript">
		function sort(columnName) {
        document.getElementById("sortColumnId").value = columnName;
        var sortOrder = document.getElementById("sortOrderId").value;
        if (sortOrder == 'asc')
            document.getElementById("sortOrderId").value = 'desc';
        else
            document.getElementById("sortOrderId").value = 'asc';
        document.forms['main'].action="new.htm";
        document.forms['main'].submit();
    	}
		function enableProceed(){
			var isChecked = false;
			$(".checkboxes").each(function() {
				 if($(this).attr('checked')){
					 isChecked = true;
				 }
			});
			enableApprove(isChecked);
		}
		function enableApprove(toDisable){
			if(toDisable)
				document.getElementById("approve_button").removeAttribute('disabled');
			else
				document.getElementById("approve_button").setAttribute('disabled','disabled');
		}
	</script>
</head>

<body>
<div class="page">
    <%@include file="../top_menu.jsp" %>
    <table width=100%>
         <tr>
	        	<td><c:import url="/WEB-INF/jsp/menu/transaction_menu.jsp" /></td>
     	</tr>
        <tr>
            <td>
                <%@include file="/WEB-INF/jsp/include/messages.jsp" %>
                <br/></td>
        </tr>
    </table>
    <div class="contentArea">

       <table border=0 cellpadding=0 cellspacing=0>
                <tr class="error">
                    <td><spring:message code="sp.transactionform.message.addnewpayee1"/>
                        <a href="<c:url value='/users/view_users.htm'/>"><spring:message code="sp.transactionform.message.addnewpayee2"/></a>
                        <spring:message code="sp.transactionform.message.addnewpayee3"/>
                    </td>
                </tr>
        </table>

        <c:choose>
            <c:when test="${empty transactions.transactionDetails}">
                <tr>
                    <td colspan="12"><spring:message
                            code="sp.transactionform.label.atpresenttherearenotransactiontext"/>.<br/>
                        <spring:message code="sp.transactionform.label.ifyouwereexpectingsometransactiontext"/>
                    </td>
                </tr>
                
            </c:when>
            <c:otherwise>
                <table border=0 cellpadding=0 cellspacing=0>
                    <tr>
                        <td >
                        	<span style="font-weight: bold;"><spring:message code="sp.transactionform.label.approvepayment"/>:</span> 
                        	 <spring:message code="sp.transactionform.label.approvepayment.note"/>
                        </td>
                    </tr>
                    <tr><td></td></tr>
                    <tr>
                        <td style="font-weight: bold; color: red;">
                        	 <spring:message code="sp.transactionform.label.user.note"/>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2"><h5>STEP 1 of 2</h5></td>
                    </tr>
                </table>
                <form:form id="main" commandName="transactions" method="post" action="step1.htm">
                    <c:set var="numberOfPayees" value="${fn:length(transactions.payeeMap)}"/>
					<form:hidden id="sortColumnId" path="sortColumn" />
					<form:hidden id="sortOrderId" path="sortOrder" />
                    <table border=0 cellpadding=4 cellspacing=1 width=100% bgcolor="#D7D7D7">
                        <tr>
                            <td colspan="6">&nbsp;</td>
                        </tr>
                        <tr bgcolor="#FAFAF7">
                            <td align="center" rowspan="3" style="font-weight: bold;">
                            	<!-- new.htm?sortColumn=SSN&sortOrder=desc -->
                            	<a href="#" onclick="sort('SSN')"><spring:message code="sp.transactionform.label.ssn"/></a>
                           	</td>
                            <td align="center" rowspan="3" style="font-weight: bold;">
                            	<a href="#" onclick="sort('name')"><spring:message code="sp.transactionform.label.customername"/></a></td>
                            <td align="center" rowspan="3" style="font-weight: bold;">
                            	<a href="#" onclick="sort('amount')"><spring:message code="sp.transactionform.label.amountreceived"/></a></td>
                            <td align="center" colspan="${numberOfPayees + 2}" style="font-weight: bold;">
                            	Miscellaneous
                                Payments
                            </td>
                            <td align="center" rowspan="3" style="font-weight: bold;">
                            	Select <a href="#" onclick="ch_select(true); enableApprove(true);">All</a>
                                /<a href="#" onclick="ch_select(false); enableApprove(false);">None</a>
                            </td>
                            
                        </tr>

                        <tr bgcolor="#FAFAF7">
                            <td align="center" rowspan="2" style="font-weight: bold;"><spring:message
                                    code="sp.transactionform.label.svcfee"/></td>
                            <td align="center" rowspan="2" style="font-weight: bold;"><spring:message
                                    code="sp.transactionform.label.selffee"/></td>
                            <c:if test="${numberOfPayees > 0}">
                                <td align="center" colspan="${numberOfPayees}" style="font-weight: bold;">
                                   <a href="<c:url value='/users/view_users.htm'/>">
                                   		<spring:message code="sp.transactionform.label.payeename"/>
                                   </a>
                                </td>
                            </c:if>
                        </tr>

                        <tr bgcolor="#FAFAF7">
                            <c:forEach var="payee" items="${transactions.payeeMap}">
                                <td align="center"
                                    style="font-weight: bold;">${payee.value.firstName} ${payee.value.lastName}</td>
                            </c:forEach>
                        </tr>

                        <c:forEach var="transaction" items="${transactions.transactionDetails}" varStatus="i">
                            <tr bgcolor="#FFFFFF">
                                <td align="left">${transaction.value.customerSSN}
                                    <form:hidden path="transactionDetails[${transaction.key}].customerSSN"/></td>
                                <td align="left">${transaction.value.customerName}
                                    <form:hidden path="transactionDetails[${transaction.key}].customerName"/></td>

                                <td align="right"><form:input path="transactionDetails[${transaction.key}].amount" 
                                                              disabled="true" cssClass="disabled"/>
                                    <form:hidden path="transactionDetails[${transaction.key}].amount"/></td>

                                <td align="right"><form:input path="transactionDetails[${transaction.key}].serviceFee"
                                                              disabled="true" cssClass="disabled"/>
                                    <form:hidden path="transactionDetails[${transaction.key}].serviceFee"/></td>

                                <td align="right"><form:input path="transactionDetails[${transaction.key}].selfFee"
                                                              size="5" cssErrorClass="errorneous"/></td>
                                <!-- SELF fee -->

                                <c:forEach var="payee" items="${transactions.payeeMap}" varStatus="p">
                                    <td align="right"><form:input
                                            path="transactionDetails[${transaction.key}].amounts[${payee.key}]" size="5"
                                            cssErrorClass="errorneous"/></td>
                                    <!-- Payee fee -->
                                </c:forEach>
                                <td align="center">
                                	<form:checkbox path="transactionDetails[${transaction.key}].checked" cssClass="checkboxes" onchange="enableProceed();"/></td>
                            </tr>
                        </c:forEach>
                        <tr bgcolor="#FAF7F7">
                            <td colspan="16" style="font-weight: bold;"><form:errors path="*" cssClass="errors"/><br>
                                <spring:message code="sp.transactionform.label.messageoftheday"/></td>
                        </tr>
                        <tr bgcolor="#FAF7F7">
                            <td colspan="16" style="color: green; font-weight: bold;">NOTE: ALL THE UNCHECKED / NON
                                SELECTED TRANSACTIONS WILL BE AUTO RETURNED TO THE "NEW TRANSACTIONS" PAGE.
                            </td>
                        </tr>
                        <tr bgcolor="#FAF7F7">
                            <td colspan="16" style="color: green; font-weight: bold;">IF YOU WANT TO CHANGE PAYEES FOR
                                CERTAIN TRANSACTIONS THEN YOU CAN UNCHECK THOSE TRANSACTIONS AND CONTINUE TO PROCESS THE
                                REST. THE UN-CHECKED ROWS WILL BE AUTO MOVE BACK TO "NEW TRANSACTIONS" PAGE. AFTER YOU
                                ARE DONE PROCESSING THE SELECTED ROWS, YOU MAY LATER VISIT THE "NEW TRANSACTIONS" PAGE
                                TO MAKE YOUR CHANGES.
                            </td>
                        </tr>
                        <tr bgcolor="#FAF7F7">
                            <td colspan="16" style="color: green; font-weight: bold;">IF YOU WANT TO CHANGE PAYMENT
                                AMOUNTS THEN SIMPLY CLICK "Edit Payment Amounts". ALL THESE ROWS WILL SHOW UP IN THE
                                EDIT PAGE. SO DOES NOT MATTER WHETER USER SELECTED ANY ROW OR NOT. HENCE ALL THE ROWS
                                WILL SHOW UP FOR EDITING.....
                            </td>
                        </tr>
                        <tr bgcolor="#FAF7F7">
                            <td colspan="16" style="color: green; "></td>
                            <td>&nbsp;</td>
                        </tr>
                         <tr>
                            <td colspan="16" align="left" style="padding-left:25px;" width="100%"><br/>
                                <c:choose>
                                	<c:when test="${transactions.isIncompleteTransaction}">
                                		<c:choose>
                                			<c:when test='${transactions.incompleteStep == "step1"}'>
                                			<input type="button" class='ui-button ui-state-default ui-corner-all' style="color: red" onclick="window.location.href='step1.htm'" value="<spring:message code="sp.transactionform.label.transaction.incomplete"/>"/>
                                			</c:when>
                                			<c:otherwise>
                                				<input type="button" class='ui-button ui-state-default ui-corner-all' style="color: red" onclick="window.location.href='step2.htm'" value="<spring:message code="sp.transactionform.label.transaction.incomplete"/>"/>
                                			</c:otherwise>
                               			</c:choose>
                                	</c:when>
                                	<c:otherwise> 
                                		<input type="submit" name="Approve" id="approve_button" value="<spring:message code="sp.transactionform.label.approvepayment.button"/>"
                                       class='ui-button ui-state-default ui-corner-all'/>
                                	</c:otherwise>
                                </c:choose> 
                                
                                <input type="submit" name="button_Move_To_Do_Not_belong" value='<spring:message code="sp.transactionform.label.moveTransactionDoNotBelongToMe"/>'
                                       class='ui-button ui-state-default ui-corner-all'/>
                                <input type="submit" name="button_Move_To_Needing_To_Return" value='<spring:message code="sp.transactionform.label.needingToReturnedBack"/>'
                                       class='ui-button ui-state-default ui-corner-all'/>
                                <input type="submit" name="button_Move_To_New_Needing_Match" value='<spring:message code="sp.transactionform.label.moveToTransactionNeedingAMatch"/>'
                                       class='ui-button ui-state-default ui-corner-all'/>
                            </td>
                        </tr> 
                    </table>
                </form:form>
            </c:otherwise>
        </c:choose>
        <div id="error" class="errors"></div>
    </div>
</div>
<%@include file="/WEB-INF/jsp/include/footer.jsp" %>
</body>
</html>